using Circus.CodeEditor;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
namespace Circus.Syntax
{
	[Serializable]
	public class SyntaxErrors : SortList<SyntaxError>
	{
		public virtual bool PositionChanged(int x, int y, int deltaX, int deltaY)
		{
			bool result = false;
			foreach (SyntaxError current in this)
			{
				Range range = current.Range;
				Point point = range.StartPoint;
				if (deltaY == 0 && point.Y > y)
				{
					break;
				}
				if (Range.UpdatePos(x, y, deltaX, deltaY, ref point, false))
				{
					range.StartPoint = point;
					result = true;
				}
				point = range.EndPoint;
				if (Range.UpdatePos(x, y, deltaX, deltaY, ref point, true))
				{
					range.EndPoint = point;
					result = true;
				}
			}
			return result;
		}
		public virtual bool BlockDeleting(Rectangle rect)
		{
			bool result = false;
			for (int i = base.Count - 1; i >= 0; i--)
			{
				Range range = base[i].Range;
				if (SortList<SyntaxError>.InsideRange(range.StartPoint, rect) && SortList<SyntaxError>.InsideRange(new Point(Math.Max(range.EndPoint.X - 1, 0), range.EndPoint.Y), rect))
				{
					base.RemoveAt(i);
					result = true;
				}
			}
			return result;
		}
		public virtual bool PositionChanged(int x, int y, int deltaX, int deltaY, IComparer<SyntaxError> comparer)
		{
			bool result = false;
			int num;
			if (!base.FindLast(new SyntaxError(new Point(x, y)), out num, comparer))
			{
				num--;
			}
			for (int i = Math.Max(num, 0); i < base.Count; i++)
			{
				SyntaxError syntaxError = base[i];
				Point position = syntaxError.Position;
				Point endPoint = syntaxError.Range.EndPoint;
				if (deltaY == 0 && position.Y > y)
				{
					break;
				}
				if (SortList<SyntaxError>.UpdatePos(x, y, deltaX, deltaY, ref position, false))
				{
					syntaxError.Position = position;
					result = true;
				}
				if (SortList<SyntaxError>.UpdatePos(x, y, deltaX, deltaY, ref endPoint, true))
				{
					syntaxError.Range.EndPoint = endPoint;
					result = true;
				}
			}
			return result;
		}
		public virtual bool BlockDeleting(Rectangle rect, IComparer<SyntaxError> comparer)
		{
			bool result = false;
			int num;
			if (base.FindLast(new SyntaxError(new Point(rect.Right, rect.Bottom)), out num, comparer))
			{
				num++;
			}
			for (int i = Math.Min(num, base.Count - 1); i >= 0; i--)
			{
				SyntaxError syntaxError = base[i];
				if (syntaxError.Position.Y < rect.Top)
				{
					break;
				}
				if (SortList<SyntaxError>.InsideRange(syntaxError.Position, rect) && SortList<SyntaxError>.InsideRange(syntaxError.Range.EndPoint, rect, true))
				{
					base.RemoveAt(i);
					result = true;
				}
			}
			return result;
		}
		public virtual bool FindErrorAt(Point position, bool exact, out int index, IComparer<SyntaxError> comparer)
		{
			bool flag = base.FindLast(new SyntaxError(position), out index, comparer);
			bool result;
			if (!exact && !flag)
			{
				index--;
				if (index >= 0 && index < base.Count)
				{
					SyntaxError syntaxError = base[index];
					Point position2 = syntaxError.Position;
					Point endPoint = syntaxError.Range.EndPoint;
					if ((position2.Y < position.Y || (position2.Y == position.Y && position2.X <= position.X)) && (endPoint.Y > position.Y || (endPoint.Y == position.Y && endPoint.X >= position.X)))
					{
						result = true;
						return result;
					}
				}
			}
			result = flag;
			return result;
		}
	}
}
